/*
 * Created by the DBAccessor generator.
 * Programmer: Lennart Martens
 * Date: 08/08/2012
 * Time: 21:02:26
 */
package com.compomics.proteocloud.db.accessor;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;

import com.compomics.util.db.interfaces.Deleteable;
import com.compomics.util.db.interfaces.Persistable;
import com.compomics.util.db.interfaces.Retrievable;
import com.compomics.util.db.interfaces.Updateable;

/*
 * CVS information:
 *
 * $Revision: 1.4 $
 * $Date: 2007/07/06 09:41:53 $
 */

/**
 * This class is a generated accessor for the Consensushit table.
 *
 * @author DBAccessor generator class (Lennart Martens).
 */
public class ConsensushitTableAccessor implements Deleteable, Retrievable, Updateable, Persistable {

	/**
	 * This variable tracks changes to the object.
	 */
	protected boolean iUpdated = false;

	/**
	 * This variable can hold generated primary key columns.
	 */
	protected Object[] iKeys = null;

	/**
	 * This variable represents the contents for the 'consensushitid' column.
	 */
	protected long iConsensushitid = Long.MIN_VALUE;


	/**
	 * This variable represents the contents for the 'l_spectrumid' column.
	 */
	protected long iL_spectrumid = Long.MIN_VALUE;


	/**
	 * This variable represents the contents for the 'l_xtandemhitid' column.
	 */
	protected long iL_xtandemhitid = Long.MIN_VALUE;


	/**
	 * This variable represents the contents for the 'l_omssahitid' column.
	 */
	protected long iL_omssahitid = Long.MIN_VALUE;


	/**
	 * This variable represents the contents for the 'l_inspecthitid' column.
	 */
	protected long iL_inspecthitid = Long.MIN_VALUE;


	/**
	 * This variable represents the contents for the 'l_cruxhitid' column.
	 */
	protected long iL_cruxhitid = Long.MIN_VALUE;


	/**
	 * This variable represents the contents for the 'protein' column.
	 */
	protected String iProtein = null;


	/**
	 * This variable represents the contents for the 'sequence' column.
	 */
	protected String iSequence = null;


	/**
	 * This variable represents the contents for the 'votes' column.
	 */
	protected long iVotes = Long.MIN_VALUE;


	/**
	 * This variable represents the contents for the 'qvalue' column.
	 */
	protected Number iQvalue = null;


	/**
	 * This variable represents the contents for the 'creationdate' column.
	 */
	protected java.sql.Timestamp iCreationdate = null;


	/**
	 * This variable represents the contents for the 'modificationdate' column.
	 */
	protected java.sql.Timestamp iModificationdate = null;


	/**
	 * This variable represents the key for the 'consensushitid' column.
	 */
	public static final String CONSENSUSHITID = "CONSENSUSHITID";

	/**
	 * This variable represents the key for the 'l_spectrumid' column.
	 */
	public static final String L_SPECTRUMID = "L_SPECTRUMID";

	/**
	 * This variable represents the key for the 'l_xtandemhitid' column.
	 */
	public static final String L_XTANDEMHITID = "L_XTANDEMHITID";

	/**
	 * This variable represents the key for the 'l_omssahitid' column.
	 */
	public static final String L_OMSSAHITID = "L_OMSSAHITID";

	/**
	 * This variable represents the key for the 'l_inspecthitid' column.
	 */
	public static final String L_INSPECTHITID = "L_INSPECTHITID";

	/**
	 * This variable represents the key for the 'l_cruxhitid' column.
	 */
	public static final String L_CRUXHITID = "L_CRUXHITID";

	/**
	 * This variable represents the key for the 'protein' column.
	 */
	public static final String PROTEIN = "PROTEIN";

	/**
	 * This variable represents the key for the 'sequence' column.
	 */
	public static final String SEQUENCE = "SEQUENCE";

	/**
	 * This variable represents the key for the 'votes' column.
	 */
	public static final String VOTES = "VOTES";

	/**
	 * This variable represents the key for the 'qvalue' column.
	 */
	public static final String QVALUE = "QVALUE";

	/**
	 * This variable represents the key for the 'creationdate' column.
	 */
	public static final String CREATIONDATE = "CREATIONDATE";

	/**
	 * This variable represents the key for the 'modificationdate' column.
	 */
	public static final String MODIFICATIONDATE = "MODIFICATIONDATE";




	/**
	 * Default constructor.
	 */
	public ConsensushitTableAccessor() {
	}

	/**
	 * This constructor allows the creation of the 'ConsensushitTableAccessor' object based on a set of values in the HashMap.
	 *
	 * @param	aParams	HashMap with the parameters to initialize this object with.
	 *		<i>Please use only constants defined on this class as keys in the HashMap!</i>
	 */
	public ConsensushitTableAccessor(HashMap aParams) {
		if(aParams.containsKey(CONSENSUSHITID)) {
			this.iConsensushitid = ((Long)aParams.get(CONSENSUSHITID)).longValue();
		}
		if(aParams.containsKey(L_SPECTRUMID)) {
			this.iL_spectrumid = ((Long)aParams.get(L_SPECTRUMID)).longValue();
		}
		if(aParams.containsKey(L_XTANDEMHITID)) {
			this.iL_xtandemhitid = ((Long)aParams.get(L_XTANDEMHITID)).longValue();
		}
		if(aParams.containsKey(L_OMSSAHITID)) {
			this.iL_omssahitid = ((Long)aParams.get(L_OMSSAHITID)).longValue();
		}
		if(aParams.containsKey(L_INSPECTHITID)) {
			this.iL_inspecthitid = ((Long)aParams.get(L_INSPECTHITID)).longValue();
		}
		if(aParams.containsKey(L_CRUXHITID)) {
			this.iL_cruxhitid = ((Long)aParams.get(L_CRUXHITID)).longValue();
		}
		if(aParams.containsKey(PROTEIN)) {
			this.iProtein = (String)aParams.get(PROTEIN);
		}
		if(aParams.containsKey(SEQUENCE)) {
			this.iSequence = (String)aParams.get(SEQUENCE);
		}
		if(aParams.containsKey(VOTES)) {
			this.iVotes = ((Long)aParams.get(VOTES)).longValue();
		}
		if(aParams.containsKey(QVALUE)) {
			this.iQvalue = (Number)aParams.get(QVALUE);
		}
		if(aParams.containsKey(CREATIONDATE)) {
			this.iCreationdate = (java.sql.Timestamp)aParams.get(CREATIONDATE);
		}
		if(aParams.containsKey(MODIFICATIONDATE)) {
			this.iModificationdate = (java.sql.Timestamp)aParams.get(MODIFICATIONDATE);
		}
		this.iUpdated = true;
	}


	/**
	 * This constructor allows the creation of the 'ConsensushitTableAccessor' object based on a resultset
	 * obtained by a 'select * from Consensushit' query.
	 *
	 * @param	aResultSet	ResultSet with the required columns to initialize this object with.
	 * @exception	SQLException	when the ResultSet could not be read.
	 */
	public ConsensushitTableAccessor(ResultSet aResultSet) throws SQLException {
		this.iConsensushitid = aResultSet.getLong("consensushitid");
		this.iL_spectrumid = aResultSet.getLong("l_spectrumid");
		this.iL_xtandemhitid = aResultSet.getLong("l_xtandemhitid");
		this.iL_omssahitid = aResultSet.getLong("l_omssahitid");
		this.iL_inspecthitid = aResultSet.getLong("l_inspecthitid");
		this.iL_cruxhitid = aResultSet.getLong("l_cruxhitid");
		this.iProtein = (String)aResultSet.getObject("protein");
		this.iSequence = (String)aResultSet.getObject("sequence");
		this.iVotes = aResultSet.getLong("votes");
		this.iQvalue = (Number)aResultSet.getObject("qvalue");
		this.iCreationdate = (java.sql.Timestamp)aResultSet.getObject("creationdate");
		this.iModificationdate = (java.sql.Timestamp)aResultSet.getObject("modificationdate");

		this.iUpdated = true;
	}


	/**
	 * This method returns the value for the 'Consensushitid' column
	 * 
	 * @return	long	with the value for the Consensushitid column.
	 */
	public long getConsensushitid() {
		return this.iConsensushitid;
	}

	/**
	 * This method returns the value for the 'L_spectrumid' column
	 * 
	 * @return	long	with the value for the L_spectrumid column.
	 */
	public long getL_spectrumid() {
		return this.iL_spectrumid;
	}

	/**
	 * This method returns the value for the 'L_xtandemhitid' column
	 * 
	 * @return	long	with the value for the L_xtandemhitid column.
	 */
	public long getL_xtandemhitid() {
		return this.iL_xtandemhitid;
	}

	/**
	 * This method returns the value for the 'L_omssahitid' column
	 * 
	 * @return	long	with the value for the L_omssahitid column.
	 */
	public long getL_omssahitid() {
		return this.iL_omssahitid;
	}

	/**
	 * This method returns the value for the 'L_inspecthitid' column
	 * 
	 * @return	long	with the value for the L_inspecthitid column.
	 */
	public long getL_inspecthitid() {
		return this.iL_inspecthitid;
	}

	/**
	 * This method returns the value for the 'L_cruxhitid' column
	 * 
	 * @return	long	with the value for the L_cruxhitid column.
	 */
	public long getL_cruxhitid() {
		return this.iL_cruxhitid;
	}

	/**
	 * This method returns the value for the 'Protein' column
	 * 
	 * @return	String	with the value for the Protein column.
	 */
	public String getProtein() {
		return this.iProtein;
	}

	/**
	 * This method returns the value for the 'Sequence' column
	 * 
	 * @return	String	with the value for the Sequence column.
	 */
	public String getSequence() {
		return this.iSequence;
	}

	/**
	 * This method returns the value for the 'Votes' column
	 * 
	 * @return	long	with the value for the Votes column.
	 */
	public long getVotes() {
		return this.iVotes;
	}

	/**
	 * This method returns the value for the 'Qvalue' column
	 * 
	 * @return	Number	with the value for the Qvalue column.
	 */
	public Number getQvalue() {
		return this.iQvalue;
	}

	/**
	 * This method returns the value for the 'Creationdate' column
	 * 
	 * @return	java.sql.Timestamp	with the value for the Creationdate column.
	 */
	public java.sql.Timestamp getCreationdate() {
		return this.iCreationdate;
	}

	/**
	 * This method returns the value for the 'Modificationdate' column
	 * 
	 * @return	java.sql.Timestamp	with the value for the Modificationdate column.
	 */
	public java.sql.Timestamp getModificationdate() {
		return this.iModificationdate;
	}

	/**
	 * This method sets the value for the 'Consensushitid' column
	 * 
	 * @param	aConsensushitid	long with the value for the Consensushitid column.
	 */
	public void setConsensushitid(long aConsensushitid) {
		this.iConsensushitid = aConsensushitid;
		this.iUpdated = true;
	}

	/**
	 * This method sets the value for the 'L_spectrumid' column
	 * 
	 * @param	aL_spectrumid	long with the value for the L_spectrumid column.
	 */
	public void setL_spectrumid(long aL_spectrumid) {
		this.iL_spectrumid = aL_spectrumid;
		this.iUpdated = true;
	}

	/**
	 * This method sets the value for the 'L_xtandemhitid' column
	 * 
	 * @param	aL_xtandemhitid	long with the value for the L_xtandemhitid column.
	 */
	public void setL_xtandemhitid(long aL_xtandemhitid) {
		this.iL_xtandemhitid = aL_xtandemhitid;
		this.iUpdated = true;
	}

	/**
	 * This method sets the value for the 'L_omssahitid' column
	 * 
	 * @param	aL_omssahitid	long with the value for the L_omssahitid column.
	 */
	public void setL_omssahitid(long aL_omssahitid) {
		this.iL_omssahitid = aL_omssahitid;
		this.iUpdated = true;
	}

	/**
	 * This method sets the value for the 'L_inspecthitid' column
	 * 
	 * @param	aL_inspecthitid	long with the value for the L_inspecthitid column.
	 */
	public void setL_inspecthitid(long aL_inspecthitid) {
		this.iL_inspecthitid = aL_inspecthitid;
		this.iUpdated = true;
	}

	/**
	 * This method sets the value for the 'L_cruxhitid' column
	 * 
	 * @param	aL_cruxhitid	long with the value for the L_cruxhitid column.
	 */
	public void setL_cruxhitid(long aL_cruxhitid) {
		this.iL_cruxhitid = aL_cruxhitid;
		this.iUpdated = true;
	}

	/**
	 * This method sets the value for the 'Protein' column
	 * 
	 * @param	aProtein	String with the value for the Protein column.
	 */
	public void setProtein(String aProtein) {
		this.iProtein = aProtein;
		this.iUpdated = true;
	}

	/**
	 * This method sets the value for the 'Sequence' column
	 * 
	 * @param	aSequence	String with the value for the Sequence column.
	 */
	public void setSequence(String aSequence) {
		this.iSequence = aSequence;
		this.iUpdated = true;
	}

	/**
	 * This method sets the value for the 'Votes' column
	 * 
	 * @param	aVotes	long with the value for the Votes column.
	 */
	public void setVotes(long aVotes) {
		this.iVotes = aVotes;
		this.iUpdated = true;
	}

	/**
	 * This method sets the value for the 'Qvalue' column
	 * 
	 * @param	aQvalue	Number with the value for the Qvalue column.
	 */
	public void setQvalue(Number aQvalue) {
		this.iQvalue = aQvalue;
		this.iUpdated = true;
	}

	/**
	 * This method sets the value for the 'Creationdate' column
	 * 
	 * @param	aCreationdate	java.sql.Timestamp with the value for the Creationdate column.
	 */
	public void setCreationdate(java.sql.Timestamp aCreationdate) {
		this.iCreationdate = aCreationdate;
		this.iUpdated = true;
	}

	/**
	 * This method sets the value for the 'Modificationdate' column
	 * 
	 * @param	aModificationdate	java.sql.Timestamp with the value for the Modificationdate column.
	 */
	public void setModificationdate(java.sql.Timestamp aModificationdate) {
		this.iModificationdate = aModificationdate;
		this.iUpdated = true;
	}



	/**
	 * This method allows the caller to delete the data represented by this
	 * object in a persistent store.
	 *
	 * @param   aConn Connection to the persitent store.
	 */
	public int delete(Connection aConn) throws SQLException {
		PreparedStatement lStat = aConn.prepareStatement("DELETE FROM consensushit WHERE consensushitid = ?");
		lStat.setLong(1, iConsensushitid);
		int result = lStat.executeUpdate();
		lStat.close();
		return result;
	}


	/**
	 * This method allows the caller to read data for this
	 * object from a persistent store based on the specified keys.
	 *
	 * @param   aConn Connection to the persitent store.
	 */
	public void retrieve(Connection aConn, HashMap aKeys) throws SQLException {
		// First check to see whether all PK fields are present.
		if(!aKeys.containsKey(CONSENSUSHITID)) {
			throw new IllegalArgumentException("Primary key field 'CONSENSUSHITID' is missing in HashMap!");
		} else {
			iConsensushitid = ((Long)aKeys.get(CONSENSUSHITID)).longValue();
		}
		// In getting here, we probably have all we need to continue. So let's...
		PreparedStatement lStat = aConn.prepareStatement("SELECT * FROM consensushit WHERE consensushitid = ?");
		lStat.setLong(1, iConsensushitid);
		ResultSet lRS = lStat.executeQuery();
		int hits = 0;
		while(lRS.next()) {
			hits++;
			iConsensushitid = lRS.getLong("consensushitid");
			iL_spectrumid = lRS.getLong("l_spectrumid");
			iL_xtandemhitid = lRS.getLong("l_xtandemhitid");
			iL_omssahitid = lRS.getLong("l_omssahitid");
			iL_inspecthitid = lRS.getLong("l_inspecthitid");
			iL_cruxhitid = lRS.getLong("l_cruxhitid");
			iProtein = (String)lRS.getObject("protein");
			iSequence = (String)lRS.getObject("sequence");
			iVotes = lRS.getLong("votes");
			iQvalue = (Number)lRS.getObject("qvalue");
			iCreationdate = (java.sql.Timestamp)lRS.getObject("creationdate");
			iModificationdate = (java.sql.Timestamp)lRS.getObject("modificationdate");
		}
		lRS.close();
		lStat.close();
		if(hits>1) {
			throw new SQLException("More than one hit found for the specified primary keys in the 'consensushit' table! Object is initialized to last row returned.");
		} else if(hits == 0) {
			throw new SQLException("No hits found for the specified primary keys in the 'consensushit' table! Object is not initialized correctly!");
		}
	}
	/**
	 * This method allows the caller to obtain a basic select for this table.
	 *
	 * @return   String with the basic select statement for this table.
	 */
	public static String getBasicSelect(){
		return "select * from consensushit";
	}

	/**
	 * This method allows the caller to obtain all rows for this
	 * table from a persistent store.
	 *
	 * @param   aConn Connection to the persitent store.
	 * @return   ArrayList<ConsensushitTableAccessor>   with all entries for this table.
	 */
	public static ArrayList<ConsensushitTableAccessor> retrieveAllEntries(Connection aConn) throws SQLException {
		ArrayList<ConsensushitTableAccessor>  entities = new ArrayList<ConsensushitTableAccessor>();
		Statement stat = aConn.createStatement();
		ResultSet rs = stat.executeQuery(getBasicSelect());
		while(rs.next()) {
			entities.add(new ConsensushitTableAccessor(rs));
		}
		rs.close();
		stat.close();
		return entities;
	}



	/**
	 * This method allows the caller to update the data represented by this
	 * object in a persistent store.
	 *
	 * @param   aConn Connection to the persitent store.
	 */
	public int update(Connection aConn) throws SQLException {
		if(!this.iUpdated) {
			return 0;
		}
		PreparedStatement lStat = aConn.prepareStatement("UPDATE consensushit SET consensushitid = ?, l_spectrumid = ?, l_xtandemhitid = ?, l_omssahitid = ?, l_inspecthitid = ?, l_cruxhitid = ?, protein = ?, sequence = ?, votes = ?, qvalue = ?, creationdate = ?, modificationdate = CURRENT_TIMESTAMP WHERE consensushitid = ?");
		lStat.setLong(1, iConsensushitid);
		lStat.setLong(2, iL_spectrumid);
		lStat.setLong(3, iL_xtandemhitid);
		lStat.setLong(4, iL_omssahitid);
		lStat.setLong(5, iL_inspecthitid);
		lStat.setLong(6, iL_cruxhitid);
		lStat.setObject(7, iProtein);
		lStat.setObject(8, iSequence);
		lStat.setLong(9, iVotes);
		lStat.setObject(10, iQvalue);
		lStat.setObject(11, iCreationdate);
		lStat.setLong(12, iConsensushitid);
		int result = lStat.executeUpdate();
		lStat.close();
		this.iUpdated = false;
		return result;
	}


	/**
	 * This method allows the caller to insert the data represented by this
	 * object in a persistent store.
	 *
	 * @param   aConn Connection to the persitent store.
	 */
	public int persist(Connection aConn) throws SQLException {
		PreparedStatement lStat = aConn.prepareStatement("INSERT INTO consensushit (consensushitid, l_spectrumid, l_xtandemhitid, l_omssahitid, l_inspecthitid, l_cruxhitid, protein, sequence, votes, qvalue, creationdate, modificationdate) values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)");
		if(iConsensushitid == Long.MIN_VALUE) {
			lStat.setNull(1, 4);
		} else {
			lStat.setLong(1, iConsensushitid);
		}
		if(iL_spectrumid == Long.MIN_VALUE) {
			lStat.setNull(2, 4);
		} else {
			lStat.setLong(2, iL_spectrumid);
		}
		if(iL_xtandemhitid == Long.MIN_VALUE) {
			lStat.setNull(3, 4);
		} else {
			lStat.setLong(3, iL_xtandemhitid);
		}
		if(iL_omssahitid == Long.MIN_VALUE) {
			lStat.setNull(4, 4);
		} else {
			lStat.setLong(4, iL_omssahitid);
		}
		if(iL_inspecthitid == Long.MIN_VALUE) {
			lStat.setNull(5, 4);
		} else {
			lStat.setLong(5, iL_inspecthitid);
		}
		if(iL_cruxhitid == Long.MIN_VALUE) {
			lStat.setNull(6, 4);
		} else {
			lStat.setLong(6, iL_cruxhitid);
		}
		if(iProtein == null) {
			lStat.setNull(7, -1);
		} else {
			lStat.setObject(7, iProtein);
		}
		if(iSequence == null) {
			lStat.setNull(8, 12);
		} else {
			lStat.setObject(8, iSequence);
		}
		if(iVotes == Long.MIN_VALUE) {
			lStat.setNull(9, 4);
		} else {
			lStat.setLong(9, iVotes);
		}
		if(iQvalue == null) {
			lStat.setNull(10, 3);
		} else {
			lStat.setObject(10, iQvalue);
		}
		int result = lStat.executeUpdate();

		// Retrieving the generated keys (if any).
		ResultSet lrsKeys = lStat.getGeneratedKeys();
		ResultSetMetaData lrsmKeys = lrsKeys.getMetaData();
		int colCount = lrsmKeys.getColumnCount();
		iKeys = new Object[colCount];
		while(lrsKeys.next()) {
			for(int i=0;i<iKeys.length;i++) {
				iKeys[i] = lrsKeys.getObject(i+1);
			}
		}
		lrsKeys.close();
		lStat.close();
		// Verify that we have a single, generated key.
		if(iKeys != null && iKeys.length == 1 && iKeys[0] != null) {
			// Since we have exactly one key specified, and only
			// one Primary Key column, we can infer that this was the
			// generated column, and we can therefore initialize it here.
			iConsensushitid = ((Number) iKeys[0]).longValue();
		}
		this.iUpdated = false;
		return result;
	}

	/**
	 * This method will return the automatically generated key for the insert if 
	 * one was triggered, or 'null' otherwise.
	 *
	 * @return	Object[]	with the generated keys.
	 */
	public Object[] getGeneratedKeys() {
		return this.iKeys;
	}

}